{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 第四次练习"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "+ 请务必交到exer4文件夹下，谢绝交到master下\n",
    "+ 请不要改动任何文件，拜托\n",
    "+ 请在10月30日前提交。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "请写一下姓名和学号：\n",
    "姓名：廖明可\n",
    "学号：0165204"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目一\n",
    "一般的歌，分为主歌和副歌部分。副歌有重复，对比两大功能。这就是A－B的基本曲式形式结构。  \n",
    "请找一首你的主打歌，把歌词打印出来，重复的副歌部分，请写一个函数，调用函数打印出来。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "孤单看天上那朵云呢 银灰色\n",
      "它安静的俯瞰着我\n",
      "失散的爱它飘浮着呢 旅行着\n",
      "想飞开但又依依不舍\n",
      "魔术般的 定在那儿 特别神秘的\n",
      "剪一片云拽着 纪念曾珍惜的\n",
      "就此远去了 但是心还悬着\n",
      "剪一片云爱着 我喜欢独自记得成为一个收藏者\n",
      "偶而怀念她 也不错\n",
      "天空的叹息没有颜色 狠心的\n",
      "钻进了我的心喊我\n",
      "记忆很麻烦也很苦涩 丢下呢\n",
      "云没有名字像个孤儿\n",
      "看似快乐 流浪惯了 这么说它真的真的不负责\n",
      "剪一片云拽着 纪念曾珍惜的\n",
      "就此远去了 但是心还悬着\n",
      "剪一片云爱着 我喜欢独自记得成为一个收藏者\n",
      "偶而怀念她 也不错\n",
      "剪一片云拽着 纪念曾珍惜的\n",
      "就此远去了 但是心还悬着\n",
      "剪一片云爱着 我喜欢独自记得成为一个收藏者\n",
      "偶而怀念她 也不错\n",
      "以前深爱的 现在呢\n",
      "剪下的云呢 隐形了\n"
     ]
    }
   ],
   "source": [
    "def paper_clouds():\n",
    "    print(\"剪一片云拽着 纪念曾珍惜的\\n就此远去了 但是心还悬着\\n剪一片云爱着 我喜欢独自记得成为一个收藏者\\n偶而怀念她 也不错\" )\n",
    "print(\"孤单看天上那朵云呢 银灰色\\n它安静的俯瞰着我\\n失散的爱它飘浮着呢 旅行着\\n想飞开但又依依不舍\\n魔术般的 定在那儿 特别神秘的\")\n",
    "paper_clouds()\n",
    "print(\"天空的叹息没有颜色 狠心的\\n钻进了我的心喊我\\n记忆很麻烦也很苦涩 丢下呢\\n云没有名字像个孤儿\\n看似快乐 流浪惯了 这么说它真的真的不负责\")\n",
    "paper_clouds()\n",
    "paper_clouds()\n",
    "print(\"以前深爱的 现在呢\\n剪下的云呢 隐形了\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目二\n",
    "请写一个函数，能够计算均值、样本方差和n(自己写公式哦)。\n",
    "每次输入十个以上的数字，能够输出上述三个统计量。\n",
    "至少调用两次。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "共10个数\n",
      "均值:5.500000\n",
      "样本方差:8.250000\n",
      "\n",
      "共10个数\n",
      "均值:15.500000\n",
      "样本方差:8.250000\n"
     ]
    }
   ],
   "source": [
    "def function(*numbers):\n",
    "    average = 0\n",
    "    variance = 0\n",
    "    var_sum = 0\n",
    "    n = 0\n",
    "    sum = 0\n",
    "    for value in numbers:\n",
    "        sum = sum + value\n",
    "        n = n + 1\n",
    "    average = sum/n\n",
    "    print('\\n共%s个数'% n)\n",
    "    print('均值:%f'% average)\n",
    "    for value in numbers:\n",
    "        var_sum = var_sum + (value-average)**2\n",
    "    variance = var_sum/n\n",
    "    print('样本方差:%f'% variance)\n",
    "function(1,2,3,4,5,6,7,8,9,10)\n",
    "function(11,12,13,14,15,16,17,18,19,20)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目三\n",
    "刚才那个函数，默认的是输出均值、样本方差和n，请在后面添加一个关键词参数，让这个函数可以选择输出样本标准差或方差。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "共10个数\n",
      "均值:5.500000\n",
      "输出方差请扣1，输出标准差请扣2\n",
      "1\n",
      "方差：8.250000\n",
      "\n",
      "\n",
      "共10个数\n",
      "均值:15.500000\n",
      "输出方差请扣1，输出标准差请扣2\n",
      "2\n",
      "标准差：2.872281\n",
      "\n"
     ]
    }
   ],
   "source": [
    "def function(*numbers):\n",
    "    average = 0\n",
    "    variance = 0\n",
    "    var_sum = 0\n",
    "    n = 0\n",
    "    sum = 0\n",
    "    for value in numbers:\n",
    "        sum = sum + value\n",
    "        n = n + 1\n",
    "    average = sum/n\n",
    "    print('\\n共%s个数'% n)\n",
    "    print('均值:%f'% average)\n",
    "    for value in numbers:\n",
    "        var_sum = var_sum + (value-average)**2\n",
    "    variance = var_sum/n\n",
    "    standard_deviation = variance**(1/2)\n",
    "    print(\"输出方差请扣1，输出标准差请扣2\")\n",
    "    choice = int(input())\n",
    "    if choice == 1:\n",
    "        print('方差：%f\\n'% variance)\n",
    "    if choice == 2:\n",
    "        print('标准差：%f\\n'% standard_deviation)\n",
    "function(1,2,3,4,5,6,7,8,9,10)\n",
    "function(11,12,13,14,15,16,17,18,19,20)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目四\n",
    "刚才那个函数，请再增加三个关键词参数，让这个参数可以选择输出均值的标准误、最大值、最小值或不输出这三个统计量。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "共10个数\n",
      "均值:5.500000\n",
      "输出标准误请扣1，输出最大值请扣2，输出最小值请扣3，不输出请扣4\n",
      "1\n",
      "标准误:0.908295\n",
      "\n",
      "\n",
      "共10个数\n",
      "均值:15.500000\n",
      "输出标准误请扣1，输出最大值请扣2，输出最小值请扣3，不输出请扣4\n",
      "2\n",
      "最大值:20\n",
      "\n",
      "\n",
      "共5个数\n",
      "均值:287.400000\n",
      "输出标准误请扣1，输出最大值请扣2，输出最小值请扣3，不输出请扣4\n",
      "3\n",
      "最小值:3\n",
      "\n",
      "\n",
      "共6个数\n",
      "均值:916.833333\n",
      "输出标准误请扣1，输出最大值请扣2，输出最小值请扣3，不输出请扣4\n",
      "4\n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "def function(*numbers):\n",
    "    average = 0\n",
    "    variance = 0\n",
    "    var_sum = 0\n",
    "    n = 0\n",
    "    sum = 0\n",
    "    for value in numbers:\n",
    "        sum = sum + value\n",
    "        n = n + 1\n",
    "    average = sum/n\n",
    "    print('\\n共%s个数'% n)\n",
    "    print('均值:%f'% average)\n",
    "    for value in numbers:\n",
    "        var_sum = var_sum + (value-average)**2\n",
    "    variance = var_sum/n\n",
    "    standard_deviation = variance**(1/2)\n",
    "    standard_error = standard_deviation/(n**(1/2))\n",
    "    print(\"输出标准误请扣1，输出最大值请扣2，输出最小值请扣3，不输出请扣4\")\n",
    "    choice = int(input())\n",
    "    if choice == 1:\n",
    "        print('标准误:%f\\n'% standard_error)\n",
    "    if choice == 2:\n",
    "        print('最大值:%s\\n'% max(numbers))\n",
    "    if choice == 3:\n",
    "        print('最小值:%s\\n'% min(numbers))\n",
    "    if choice == 4:\n",
    "        print('\\n')\n",
    "function(1,2,3,4,5,6,7,8,9,10)\n",
    "function(11,12,13,14,15,16,17,18,19,20)\n",
    "function(19,81,3,27,1307)\n",
    "function(19,98,6,10,164,5204)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
